<%@ page contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>
<head>
	<title>数据分类</title>
	 <%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/import.jsp" %>
	<script type="text/javascript" src="${ctx}/js/zbxtools.js"></script>
	<script type="text/javascript">
		var inputForm = '#inputForm';
		$(function(){
			searchSubmit('sortInfo','sortList');
			$(inputForm).form({
			    onSubmit:function(){		    	
			    	return $(this).form('validate');
			    },
			    success:function(data){
			    	var result = jQuery.parseJSON(data);
			    	if(result.flag=='T'){
			    		$.messager.alert('提交结果', '操作成功', 'info',function(){
			    			parent.colseAdd();
			    			parent.reload();
			    		});	
			    	}else {
			    		$.messager.alert('提交结果', '操作失败', 'error');
			    	}        
			    }
			});
		}) ;
	
	</script>

<body>	

<div id="tip"></div>
	<form id="inputForm" name="inputForm" method="post" action="${ctx }/info/core/save.action">
		<input type="hidden" name="formToken" id="formToken" value="${formToken}"/>
		<input type="hidden" name="tempIds" id="temp_sysIds">
		<table class="datagrid-body" >
			<tr>
				<td class="datagrid-header">生成地址<font color="red">*</font></td>
				<td>
					<input id="filePath" name="filePath"  value="d:/test-portal"
					class="easyui-validatebox" data-options="required:true" style="width:220px;" 
					missingMessage="请输入生成地址"/>
				</td>
				<td rowspan="4" align="center" width="50%">
		            <a class="easyui-linkbutton" iconCls="icon-save" onclick="createProject()">生 成</a>&nbsp;&nbsp;&nbsp;
		            </td>
			</tr>
			<tr >
				<td class="datagrid-header">工程名<font color="red">*</font></td>
				<td>
					<input name="projectName" id="projectName" value="default"
					class="easyui-validatebox" style="width:220px;" data-options="required:true"
					missingMessage="请输入工程名"  />				
				</td>
			</tr>
			<!-- tr >
				<td class="datagrid-header">包路径<font color="red">*</font></td>
				<td>
					<input name="packPath"  id="packPath" value=""
					class="easyui-validatebox" style="width:220px;" data-options="required:true"
					missingMessage="请输入包路径"  />				
				</td>
			</tr -->
			<tr><td colspan="2">文件类型：<input type="radio" name="createTemplate" value="0" checked="checked">全部
		                         <input type="radio" name="createTemplate" value="1">页面
		                         <input type="radio" name="createTemplate" value="2">配置文件
		                         <%--<input type="radio" name="createTemplate" value="3">action
		                         --%>
		                         <input type="radio" name="createTemplate" value="4">entity
		                         <input type="radio" name="createTemplate" value="5">其他
		       </td></tr>
		</table>
	</form>
	
	<table id="sortList_table" class="datagrid-body" width="100%" cellspacing="0" cellpadding="0">
	<tr class="datagrid-header-row">
	    <th width="10px"><input type="checkbox" id="select_all" onclick="selectAll()"></th>
		<th>标识</th>
		<th>名称</th>
		<th>表名</th>
		<th>对象名</th>
		<th>状态</th>
	</tr>
	</table>
	<form id="sortList_form"></form>
</body>
<script type="text/template" id="sortList_html">
	<? for ( var i = 0; i < rows.length; i++) {?>
		<tr class="datagrid-row datagrid-row-alt" style="height: 25px;">
            <td><input type="checkbox" name="ids" value="<?=rows[i].sortId?>"></td>
			<td><div style="height:auto;" class="datagrid-cell datagrid-cell-c1-sortName"><?=rows[i].sortCode?></div></td>
			<td><?=rows[i].sortName?></td>
            <td><?=rows[i].infoTableName?></td>
            <td><?=rows[i].objName?></td>
			<td><?if("0"==rows[i].sortStatus){?><font color="red">未启用</font><?}else{?>已启用<?}?></td>
		</tr>
   <?}?>  		
	</script>
<script>
//查询分页列表数据
function searchSubmit(objName,listName){
 	var this_url = '${ctx}/info/core/info!data.action';
 	var formName = listName+"_form";
 	var tableName = listName+"_table";
 		$.ajax({
  		   type:'post',url:this_url, data:$("#"+formName).serialize(),dataType:'json',
  		   success: function(myData){
  			   console.log(myData);
  			   deleteAllRow(tableName);
  			   var htmlData = baidu.template(listName+'_html',eval(myData)); 
  		   	   if(eval(myData).total>0){
  				   $("#"+tableName).append(htmlData);
  		   	   }
  		  }
  	   });	
 }
function deleteAllRow(tableId){
	var tb = document.getElementById(tableId);
	if(tb){
	     var rowNum=tb.rows.length;
	     for (i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}
function selectAll(){
	  var collid = document.getElementById("select_all");
	  var coll = document.getElementsByName("ids");
	  if (collid.checked){
	     for(var i = 0; i < coll.length; i++)
	       coll[i].checked = true;
	  }else{
	     for(var i = 0; i < coll.length; i++)
	       coll[i].checked = false;
	  }
}

function createProject(sysName){
	  var coll = document.getElementsByName("ids");
	  var ids="";
	  for(var i = 0; i < coll.length; i++){
		  if(coll[i].checked){
			  ids +=coll[i].value+",";
		  }
	  }
	  alert(ids);

	  if(ids==""){
		  alert("请选择要生成的表");
		  return false;
	  }
	  var filePath = $("#filePath").val();
	  var sysName = $("#projectName").val();
	  //var packPath = $("#packPath").val();
	  if(filePath==""){
		  alert("请填写工程生成地址");
		  return false;
	  }
	  if(sysName==""){
		  alert("请填写工程名");
		  return false;
	  }
	  /*if(doNull(packPath)==""){
		  alert("请填写包路径");
		  return false;
	  }*/
	  $("#temp_sysIds").val(ids);
	  var this_url ="${ctx}/info/core/buildProject";
	  $.ajax({type:'post',url:this_url,data:$("#inputForm").serialize(),cache: false,async:false,dataType:'json',
		   success: function(myData){ alert(myData.msg); }
	  });
}
</script>
</html>